package hydrap2p.gui.commands;

import hydrap2p.gui.FilterLabelPanel;

import java.util.ArrayList;

import javax.swing.JOptionPane;

public class Cmd_FilterLabelPanel_AddNewLabel implements Command {

	@Override
	public void execute() {
		String labelName = JOptionPane.showInputDialog(null,
				"Please input the name of the new label.");
		ArrayList<String> labels = FilterLabelPanel.getInstance().getLabels();

		boolean isValid = true;

		if (labelName == null) {
			isValid = false;
		} else if (labelName.length() == 0) {
			isValid = false;
		} else if (labels.contains(labelName)) {
			isValid = false;
		}

		if (isValid) {
			labels.add(labelName);
			FilterLabelPanel.getInstance().updateLabelList();
		} else if (labelName == null) {
			// don't display the warning if they just close the input window
		} else {
			JOptionPane.showMessageDialog(null, "Invalid label name.",
					"Invalid", JOptionPane.WARNING_MESSAGE);
		}
	}

	@Override
	public String getCommand() {
		return this.getClass().getSimpleName();
	}

	@Override
	public void unexecute() {
		// TODO Auto-generated method stub

	}

}
